package com.yanjiali.controller;

import com.yanjiali.model.R;
import com.yanjiali.model.req.AddToCollectionRecordReq;
import com.yanjiali.model.req.GetCollectDataByOneDirIdReq;
import com.yanjiali.model.req.RemoveCollectionRecordsReq;
import com.yanjiali.model.resp.*;
import com.yanjiali.service.CollectContentService;
import com.yanjiali.service.CollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Package: com.yanjiali.controller
 * @Author: yanjiali
 * @Created: 2025/4/26 18:17
 */
@Api(tags = "对应收藏控制器")
@RestController
@RequestMapping("/v1/collects")
public class CollectController {

    @Autowired
    private CollectService collectService;

    @Autowired
    private CollectContentService collectContentService;

    @PostMapping("/addToCollectionRecord")
    @ApiOperation("添加收藏记录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addToCollectionRecordReq", value = "添加收藏记录请求参数")
    })
    public R<AddToCollectionRecordResp> addToCollectionRecord(@RequestBody AddToCollectionRecordReq addToCollectionRecordReq) {
        return collectService.addToCollectionRecord(addToCollectionRecordReq);
    }

    @PostMapping("/removeCollectionRecords")
    @ApiOperation("移除对应收藏的文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "removeCollectionRecordsReq", value = "移除收藏对应请求参数")
    })
    public R<RemoveCollectionRecordsResp> removeCollectionRecords(@RequestBody RemoveCollectionRecordsReq removeCollectionRecordsReq) {
        return collectService.removeCollectionRecords(removeCollectionRecordsReq);
    }

    @GetMapping("/isTheArticleFavorited")
    @ApiOperation("判断文章是否被收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "文章id")
    })
    public R<Boolean> isTheArticleFavorited(@RequestParam Long articleId) {
        return collectContentService.isTheArticleFavorited(articleId);
    }

    @PostMapping("/getCollectDataByOneDirId")
    @ApiOperation("通过一级目录的id获取对应的所有二级收藏目录（含一级）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "getCollectDataByOneDirIdReq", value = "获取一二级收藏目录的请求参数")
    })
    public R<GetCollectDataByOneDirIdResp> obtainTheCorrespondingDataThroughThePrimaryDirectoryId(@RequestBody GetCollectDataByOneDirIdReq getCollectDataByOneDirIdReq) {
        return collectService.obtainTheCorrespondingDataThroughThePrimaryDirectoryId(getCollectDataByOneDirIdReq);
    }

    @GetMapping("/searchCollectByTitle")
    @ApiOperation("通过收藏记录名称获取对应结果集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "对应收藏标题")
    })
    public R<SearchCollectByTitleResp> searchCollectByTitle(@RequestParam String title) {
        return collectContentService.searchCollectByTitle(title);
    }

    @GetMapping("/deleteASingleCollection")
    @ApiOperation("删除单个收藏内容数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对应收藏内容id")
    })
    public R deleteASingleCollection(@RequestParam String id) {
        return collectContentService.deleteASingleCollection(id);
    }

    @GetMapping("/deleteAll")
    @ApiOperation("删除所有收藏内容记录")
    public R deleteAll() {
        return collectContentService.deleteAll();
    }

    @GetMapping("/getCollectContentBySecondLevelId")
    @ApiOperation("通过二级目录id获取其中所有的收藏数据信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对应二级目录id")
    })
    public R<GetCollectContentBySecondLevelIdResp> getCollectContentBySecondLevelId(@RequestParam Long id) {
        return collectContentService.getCollectContentBySecondLevelId(id);
    }

    @GetMapping("/getAllCollectContent")
    @ApiOperation("对应获取用户所有收藏记录")
    public R<GetAllCollectContentByUserIdResp> getAllCollectContentByUserId() {
        return collectContentService.getAllCollectContentByUserId();
    }
}
